{% extends "skia_telemetry_base.html" %}

{% block content %}
  <center>
  <h2>Run Telemetry Benchmarks</h2>

  {% if not is_google_chromium_user %}
    <br/>Must have a google or chromium account to trigger benchmarks (contact rmistry@)<br/><br/>
  {% else %}
  <form action="/skia-telemetry" name="add_telemetry_task" method="post" enctype="multipart/form-data">
    <table cellpadding="5">
      <tr>
        <td>Benchmark to run</td>
        <td><input type="text" size="35" name="benchmark_name" {% if admin %}value="skpicture_printer"{% endif %}/></td>
      </tr>
      <tr>
        <td>Benchmark Arguments</td>
        <td><input type="text" size="35" name="benchmark_arguments"/></td>
      </tr>
      <tr>
        <td>Pagesets Type</td>
        <td>
          <select name="pagesets_type">
            {% for pageset_type in pageset_types %}
              <option value="{{ pageset_type }}" {% ifequal pageset_type "Deeplinks" %}disabled{% endifequal %}>{{ pageset_type }}</option>
            {% endfor %}
          </select>
      </td>
      </tr>
      <tr>
        <td>Chromium Build</td>
        <td>
          <select name="chromium_build">
            {% for chromium_build in chromium_builds %}
              <option value="{{ chromium_build.chromium_rev }}-{{ chromium_build.skia_rev }}">{{ chromium_build.chromium_rev|slice:":7" }}-{{ chromium_build.skia_rev|slice:":7" }} (Chromium rev created on {{ chromium_build.chromium_rev_date}})</option>
            {% endfor %}
          </select>
          (See Chromium Build details <a href='/skia-telemetry/chromium_builds'>here</a>)
      </td>
      </tr>
      <tr>
        <td>Whitelist File</td>
        <td><input type="file" name="whitelist_file"/> (Must contain one webpage per line)</td>
      </tr>
      <tr>
        <td>Optional Description</td>
        <td><input type="text" name="description" size="35"></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><input type="submit" value="Queue Telemetry Task"></td>
      </tr>
    </table>
  </form>
  {% endif %}
  <hr/>


  <h2>Your previous Benchmark runs</h2>
  <br/>

  {% if telemetry_tasks %}
  <table border="1" cellpadding="5">
    <tr bgcolor="#CCCCFF">
      <td><b>Description</b></td>
      <td><b>Benchmark Name</b></td>
      <td><b>Benchmark Arguments</b></td>
      <td><b>Pagesets Type</b></td>
      <td><b>Chromium Build</b></td>
      <td><b>Requested Time</b></td>
      <td><b>Completed Time</b></td>
      <td><b>Whitelist File</b></td>
      <td><b>Output Link</b></td>
      <td><b>Delete</b></td>
    </tr>
    {% for task in telemetry_tasks %}
    <tr {% if not task.completed_time %}bgcolor="#8FDF5F"{% endif %} >
      <td>{{ task.description }}</td>
      <td>{{ task.benchmark_name }}</td>
      <td>{{ task.benchmark_arguments }}</td>
      <td>{{ task.pagesets_type }}</td>
      <td>
        {% if task.chromium_rev and task.skia_rev %}
          <a href='https://chromium.googlesource.com/chromium/src/+/{{ task.chromium_rev }}'>{{ task.chromium_rev|slice:":7" }}</a>-<a href='https://skia.googlesource.com/skia/+/{{ task.skia_rev }}'>{{ task.skia_rev|slice:":7" }}</a>
        {% else %}
          N/A
        {% endif %}
      </td>
      <td>{{ task.requested_time }}</td>
      <td>
        {% if task.completed_time %}
          {{ task.completed_time }}
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        {% if task.whitelist_file %}
          <form action="/skia-telemetry/skia_telemetry_info_page" name="display_whitelist_file" method="post">
            <input type='hidden' name='whitelist_key' value='{{ task.key.id_or_name }}'>
            <input type='submit' value='Whitelist File'>
          </form>
        {% else %}
          None
        {% endif %}
      </td>
      <td align="center">
        {% if task.output_link %}
          <a href='{{ task.output_link }}' target='_blank'>output</a>
        {% else %}
          {% ifequal task.key.id_or_name oldest_pending_task_key %}
            In Progress
          {% else %}
            Waiting in Queue
          {% endifequal %}
        {% endif %}
      </td>
      <td align="center">
        <form action="/skia-telemetry" name="delete_telemetry_task" method="post">
          <input type='hidden' name='delete' value='{{ task.key.id_or_name }}'>
          <input type='submit' value='Delete' {% ifequal task.key.id_or_name oldest_pending_task_key %}disabled{% endifequal %}>
        </form>
      </td>
    </tr>
    {% endfor %}
  </table>
  {% else %}
    No Previous runs yet.
  {% endif %}
  <br/>
  <a href='/skia-telemetry/all_tasks#telemetry'>View runs of all users</a>
  </center>

{% endblock %}
